package com.itheima.job1;

import java.util.ArrayList;
import java.util.Iterator;

public class Test1 {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);
        //方式一：普通for循环遍历
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        System.out.println("------------");
        //方式二：增强for循环
        for (Integer integer : list) {
            System.out.println(integer);
        }
        System.out.println("------------");
        //方式三：迭代器遍历
        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
            Object next =  iterator.next();
            System.out.println(next);
        }
        System.out.println("------------");
        //方式四：forEach遍历
        list.forEach(l-> System.out.println(l));

    }
}
